<template>
    <el-dialog :title="isEdit ? '修改' : '新增'" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" customClass="customWidth">
        <el-form :model="ruleForm" ref="ruleForm" label-width="200px">
            <el-row :gutter="20">
                <el-col :span="50">
                    <el-form-item label="传感器类型" prop="SensortypeType">
                        <el-input v-model="ruleForm.SensortypeType"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="50">
                    <el-form-item label="单位" prop="unit">
                        <el-input v-model="ruleForm.unit"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                
                <el-col :span="50">
                    <el-form-item label="预警值" prop="alarm01">
                        <el-input v-model="ruleForm.alarm01"></el-input>
                    </el-form-item>
                </el-col>
              
            </el-row>
            <el-row :gutter="20">
                
                <el-col :span="50">
                    <el-form-item label="报警值" prop="bjvalue">
                        <el-input v-model="ruleForm.bjvalue"></el-input>
                    </el-form-item>
                </el-col>
              
            </el-row>
            <el-row :gutter="20">
              
                <el-col :span="50">
                    <el-form-item label="报表y轴上限值" prop="YMax">
                        <el-input v-model="ruleForm.YMax"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
              
                <el-col :span="50">
                    <el-form-item label="报警时的描述" prop="alarmDesc">
                        <el-input v-model="ruleForm.alarmDesc"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
              
                <el-col :span="50">
                    <el-form-item label="正常时的描述" prop="normalDesc">
                        <el-input v-model="ruleForm.normalDesc"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" :loading="loading" @click="save">确定</el-button>
        </span>
    </el-dialog>
</template>

<script>
import { Message } from 'element-ui'
import { dingbanchuanganqipeizhiadd, dingbanchuanganqixiygai } from '../../../https/api/user'
const ruleForm = {
    SensortypeType: '',
    unit: '', 
    alarm01: '', 
    YMax: '', 
    alarmDesc: '', 
    normalDesc: '',
    bjvalue:''

}
export default {
    data() {
        return {
            dialogVisible: false,
            ruleForm,
            isEdit: false,
            loading: false,
        };
    },
    methods: {
        show(data) {
            this.isEdit = !!data
            this.ruleForm = data || ruleForm
            this.dialogVisible = true
        },
        async save() {
            const api = this.isEdit ? dingbanchuanganqixiygai : dingbanchuanganqipeizhiadd
            try {
                this.loading = true
                const result = await api(this.ruleForm)
                const message = this.isEdit ? '修改成功！' : '添加成功！'
                Message({
                    message,
                    type: 'success'
                })
                this.$parent.Onlist()
                this.dialogVisible = false
                this.$refs.ruleForm.resetFields()
                console.log('>>>>', result);
            } catch (e) {
                console.log(e)
            } finally {
                this.loading = false
            }
        },
        handleClose(done) {
            // this.$confirm('确认关闭？')
            // .then(_ => {
            done();
            // })
            // .catch(_ => { });
        }
    }
}
</script>

<style scoped lang="less">
.el-select {
    width: 100%;
}
.customWidth{
    width: 30% !important;
    min-width: 100px !important;
}
</style>